<template>
	<view>
		<scroll-view scroll-y class="body-scroll-view" @scrolltolower="onreachBottom">
			<!-- 社区服务 -->
			<view class="block-title">
				<text class="left">社区服务</text>
				<navigator url="/pages/topic-cate-list/topic-cate-list" hover-class="none" class="right">
					<text>查看更多</text>
				</navigator>
			</view>
			<scroll-view :scroll-x="true">
				<view class="topic-hot">
					<navigator :url="'/pages/topic-detail/topic-detail?id='+item.id" class="topic-item"
						v-for="(item,index) in serviceList" :key="index">
						<image mode="aspectFill" class="cover-img" :src="item.cover_image"></image>
						<text>{{item.topic_name}}</text>
					</navigator>
				</view>
			</scroll-view>
			<!-- 热门精选 -->
			<view class="block-title">
				<text class="left">闲置社区</text>
				<view class="right">
					<!-- <text>为你推荐更好的内容</text> -->
				</view>
			</view>
			<post-list :list="postList" :loadStatus="loadStatus"></post-list>
		</scroll-view>
		<!-- 发布按钮 -->
		<navigator url="/pages/plus-post/plus-post" class="plus-box">
			<text class="iconfont iconjia" style="color: #FFFFFF;"></text>
		</navigator>
	</view>
</template>

<script>
	import postList from '../components/post-list/post-list.vue';
	export default {
		components: {
			postList
		},
		data() {
			return {
				loadStatus: "loadmore",
				postList: [],
				serviceList: [],
				page_num: 1,
				page_size: 10
			}
		},
		methods: {
			// 获取轮播图
			getForumList() {
				this.loadStatus = "loading";
				let data = {
					page: this.page_num,
					page_size: this.page_size
				};
				this.$api.sendRequest({
					url: '/forum/api/forum/getForumList',
					data: data,
					success: res => {
						if (res.code == 0 && res.data) {
							let newArr = res.data.list.length ? res.data.list : [];
							
							//设置列表数据
							if (this.page_num == 1) this.postList = []; //如果是第一页需手动制空列表
							this.postList = this.postList.concat(newArr); //追加新数1据
							++this.page_num;
							
							if (res.data.current_page === res.data.last_page || res.data.last_page === 0) {
								this.loadStatus = "nomore";
							} else {
								this.loadStatus = "loadmore"
							}
						} 
					},
					fail() {

					}
				});
			},
			// 获取社区服务
			getServiceList() {
				this.$api.sendRequest({
					url: '/forum/api/service/getServiceList',
					data: {},
					success: res => {
						if (res.code == 0 && res.data) {
							this.serviceList = res.data;
						} 
					},
					fail() {
						
					}
				});
			},
			// scroll-view到底部加载更多
			onreachBottom() {
			
			}
		},
		onLoad() {
			this.getForumList();
			this.getServiceList();
		},
	}
</script>

<style lang="scss" scoped>
	@import "index.scss";
</style>
